from PySide6.QtCore import QDateTime, Slot, Qt
from PySide6.QtWidgets import QMessageBox, QDialog, QTableWidgetItem, QMainWindow, QButtonGroup
from PySide6.QtGui import QIcon, QColor

from Devices.Chiot.BsDevs.ComDev.Forms.ComDevWindow import ComDevWindow
from Devices.Chiot.BsDevs.Door.DoorDevice import DoorDevice
from Devices.Chiot.BsDevs.Door.DoorParser import DoorParser
from Devices.Chiot.BsDevs.Door.Forms.DoorWindow_UI import Ui_FormDoorWindow
from Components.MessageBoxFunc import MessageBoxFunc

class DoorWindow(ComDevWindow):
    # 0、窗体初始化、状态变量初始化
    def __init__(self, supportDevice, parent = None):
        # 注意在实现特有设备时，一定要先将其ui对象加载完毕
        super().__init__(supportDevice, parent)

        self.FullStatus = DoorDevice.DoorFullStatus()

        self._ui = Ui_FormDoorWindow()
        self._ui.setupUi(self)
        self.initUiWindow()
        self.SetupUi(self._ui)
        # self.testUi()

    # 1、数据解析
    def setHeartbeatStatus(self):
        pass

    def CmdRptStatusReceived(self, msgValue):
        if DoorParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdHeartbeatReceived(self, msgValue):
        if DoorParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdFullStatusReceived(self, msgValue):
        pass

    def CmdMsgValueReceived(self, msgName, msgValue):
        pass

    # 2、运行状态
    def setFullStatus(self):
        self._ui.label_sensorStatus.setText("开启" if self.FullStatus.sensorStatus else "关闭")
        self._ui.label_powerWarn.setText("告警" if self.FullStatus.powerWarn else "未告警")
        self._ui.label_batteryPercentage.setText(str(self.FullStatus.batteryPercentage) + "%")
        self._ui.label_checkStatus.setText("正在自检" if self.FullStatus.checkStatus else "未自检")
                              
